#!/bin/bash

# set the CC and CXX, usually it is not needed as cmake can detect it
# set CC and CXX to mpicc and mpic++ when enable gasnet
# CC=mpicc
# CXX=mpic++

# add flags if needed
#CC_FLAGS=${CC_FLAGS+=""}
#NVCC_FLAGS=${NVCC_FLAGS+=""}
#LD_FLAGS=${LD_FLAGS+=""}

#set install dir
#INSTALL_DIR=

# set build type
BUILD_TYPE=Release

# set CUDA Arch with your GPU architecture
FF_CUDA_ARCH=${FF_CUDA_ARCH:-""}

# set CUDNN dir in case cmake cannot autodetect a path
CUDNN_DIR=${CUDNN_DIR:-"/usr/local/cuda"}

# set CUDA dir in case cmake cannot autodetect a path
CUDA_DIR=${CUDA_DIR:-"/usr/local/cuda"}

# enable Python
FF_USE_PYTHON=${FF_USE_PYTHON:-ON}

# enable GASNet
FF_USE_GASNET=${FF_USE_GASNET:-OFF}

# select GASNET conduit
FF_GASNET_CONDUIT=${FF_GASNET_CONDUIT:-ibv}

# build C++ examples
FF_BUILD_ALL_EXAMPLES=${FF_BUILD_ALL_EXAMPLES:-OFF}

# build C++ unit tests
FF_BUILD_UNIT_TESTS=${FF_BUILD_UNIT_TESTS:-OFF}

# use precompiled NCCL and Legion libraries, where available
FF_USE_PREBUILT_NCCL=${FF_USE_PREBUILT_NCCL:-ON}
FF_USE_PREBUILT_LEGION=${FF_USE_PREBUILT_LEGION:-ON}
# use the flag below to use both the NCCL and Legion pre-built libraries.
# when the flag below is set to ON, the two flags above are ignored.
FF_USE_ALL_PREBUILT_LIBRARIES=${FF_USE_ALL_PREBUILT_LIBRARIES:-OFF}

# enable avx2
FF_USE_AVX2=${FF_USE_AVX2:-OFF}

# set MAX_DIM
FF_MAX_DIM=${FF_MAX_DIM:-5}

# set ROCM path
ROCM_PATH=${ROCM_PATH:-"/opt/rocm"}

# set GPU backend
FF_GPU_BACKEND=${FF_GPU_BACKEND:-cuda}
if [[ "${FF_GPU_BACKEND}" != @(cuda|hip_cuda|hip_rocm|intel) ]]; then
  echo "Error, value of FF_GPU_BACKEND (${FF_GPU_BACKEND}) is invalid."
  exit 1
elif [[ "$FF_GPU_BACKEND" == "cuda" || "$FF_GPU_BACKEND" = "hip_cuda" ]]; then
    # enable NCCL
    FF_USE_NCCL=${FF_USE_NCCL:-ON}
else
    FF_USE_NCCL=OFF
fi

. $(dirname $0)/config.inc

if [ -n "$1" ]; then
    # You can pass the name of the variable you want to print out as $1. This
    # is used in the python setup script to get the cmake config
    echo "${!1}"
else
    run_cmake $*
fi
